package vip.xiaonuo.bi.modular.dataset.dispatcher;

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.Map;

@Component
public class InvokeDataSetProcess implements InitializingBean, ApplicationContextAware {


    Map<String,DataSetClient> nodeInstant = new HashMap<>();
    private ApplicationContext applicationContext;

    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        this.applicationContext = applicationContext;
    }

    @Override
    public void afterPropertiesSet() {
        Map<String, DataSetClient> beanMap = applicationContext.getBeansOfType(DataSetClient.class);
        //遍历该接口的所有实现，将其放入map中
        for (DataSetClient serviceImpl : beanMap.values()) {
            nodeInstant.put(serviceImpl.getDataSetType(), serviceImpl);
        }
    }

    public  DataSetClient getTarget(String type) {
        return this.nodeInstant.get(type);
    }

}